<?php 
namespace app\wx\controller;

use think\Exception;
use think\Controller;
use think\Db;

// 异常处理模块
use app\common\exception\BaseException;
use app\wx\model\Comment as CommentModel;

class Comment extends Controller {
  public function addComment() {
    $comment = new CommentModel();
    $data = $comment::where('book_id', $this->request->param('id'))->where('content', $this->request->param('value'))->find();
    // 短评已存在
    if($data) {
      $data->nums = $data->nums + 1;
      $result = $data->save();
    } else {
      $comment->book_id = $this->request->param('id');
      $comment->nums = 0;
      $comment->content = $this->request->param('value');
      $result = $comment->save();
    }
    if($result) {
      return json([
        "msg"=> "查找成功",
        "code"=> 20000
      ],200);
    }
  }
}